package com.xjgc.msibase.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xjgc.msibase.entity.MsiExoTask;
import com.xjgc.msibase.entity.MsiExoTaskServer;
import com.xjgc.msibase.service.IMsiExoTaskServerService;
import com.xjgc.msibase.service.IMsiExoTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoDict;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 对外任务
 *
 * @Description: 对外任务
 * @Author: 小逗号
 * @Date: 2023-10-30
 * @Version: V1.0
 */
@Api(tags = "对外任务")
@RestController
@RequestMapping("/msibase/msiExoTask")
@Slf4j
public class MsiExoTaskController extends JeecgController<MsiExoTask, IMsiExoTaskService> {
    @Resource
    private IMsiExoTaskService msiExoTaskService;
    @Resource
    private IMsiExoTaskServerService msiExoTaskServerService;


    /**
     * 分页列表查询
     *
     * @param queryAo
     * @param pageNo
     * @param pageSize
     * @return
     */
    @ApiOperation(value = "对外任务-分页列表查询", notes = "对外任务-分页列表查询")
    @AutoDict
    @GetMapping(value = "/list")
    public Result<IPage<MsiExoTask>> queryPageList(MsiExoTask queryAo,
                                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize
    ) {
        IPage<MsiExoTask> page = msiExoTaskService.queryPage(new Page<MsiExoTask>(pageNo, pageSize), queryAo);
        return Result.OK(page);
    }

    @ApiOperation(value = "对外任务-新增", notes = "对外任务-新增")
    @PostMapping("/add")
    public Result<?> add(@RequestBody MsiExoTask addAo) {
        msiExoTaskService.save(addAo);
        return Result.OK();
    }

    @ApiOperation(value = "对外任务-编辑修改", notes = "对外任务-编辑修改")
    @PutMapping("/edit")
    public Result<?> edit(@RequestBody MsiExoTask editAo) {
        msiExoTaskService.updateById(editAo);
        return Result.OK();
    }
    @PostMapping("/addTaskServer")
    public Result<?> addTaskServer(@RequestBody MsiExoTaskServer msiExoTaskServer){
        msiExoTaskServerService.save(msiExoTaskServer);
        return Result.OK("任务接口关联成功!");
    }

    @ApiOperation(value = "对外任务-测试")
    @PostMapping("/exoTaskTest")
    public Result<?> exoTaskTest(@RequestBody MsiExoTask testDto) {
        String testRequest = testDto.getTestRequest();
        if (StringUtils.isBlank(testRequest)) {
            return Result.error("缺少数据!");
        }
        Result<?> result = msiExoTaskService.execute(testDto, testRequest);
        return result;
    }
}
